const express        = require('express');
const router = express.Router();

const bodyParser     = require('body-parser');
const cors = require('cors');
var multer  = require('multer')
var upload = multer({ dest: './uploads/trancenter/yyzz/' })

router.use(cors());
// router.use(bodyParser.urlencoded({ extended: false }))
// router.use(bodyParser.json())


router.get('/api/user/showcompany', (req, res) => {
    var obj = {
        "user_id":19,
        "name":"1",
        "linkman":"1",
        "linkphone":1,
        "address":"1",
        "license_id":"1",
        "license_pic": "www.talenmall.com\/tp5full\/public\/upload\/company\/19\/bg.gif",
        "chairman": ""
    };
    res.header('content-type', 'routerlication/json');
    res.send(obj);
})

router.post('/api/uploadyyzz', upload.single('file'), (req, res, next)=>{
    res.send({code: 200, files: req.file});
});

router.use('/api/user/savecompany', bodyParser.urlencoded({ extended: false }))
router.post('/api/user/savecompany', (req, res)=>{
    res.send(req.body);
})

router.get('/api/user/islogin', (req, res)=>{
    if(new Date().getTime() % 2 > 0){
        res.send({
            "nickname":"橘子",
            "phone":"17070707070"
        })
    }else{
        // res.send({
        //     "nickname":'橘子',
        //     "phone":"17070707070"
        // })
        res.send({
            "code":0,
            "msg":"请重新登陆",
            "data":"",
            "url":"http:\/\/www.talenmall.com\/Logins.html",
            "wait":3
        })
    }
})

router.post('/api/login/login', bodyParser.urlencoded({extended: false}),
            (req, res)=>{
    if(new Date().getTime() % 2 > 0){
        res.send({
            "code":0,
            "msg":"账号不存在",
            "data":"",
            "url":"javascript:history.back(-1);",
            "wait":3
        })
    }else{
        res.send({
            "success": req.body.phone
        });
    }
})

module.exports = router;